<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        body {
            height: 3000px;
        }

        div {
            position: fixed;
            right: 50px;
            bottom: 100px;
        }
    </style>
</head>
<body>

    <div id="goBack">返回顶部</div>

    <script>

        // 
        var oDiv = document.getElementById('goBack') ;


        
        oDiv.onclick = function() {
            // 
            // document.documentElement.scrollTop = 0 ;
            var t = setInterval(function(){
                document.documentElement.scrollTop-=3;
                if(document.documentElement.scrollTop <= 0) {
                    clearInterval(t) ;
                }
            } , 10)
        }

    </script>
        
</body>
</html>